<!--
 * @Author: HeAo
 * @Date: 2021-10-12 11:43:46
 * @LastEditTime: 2021-10-12 11:51:10
 * @LastEditors: HeAo
 * @Description: 
 * @FilePath: \web2103-2105\web2105\3-2-Vue\day04\7-过滤器.html
 * 别乱动！
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../js/vue.js"></script>
</head>

<body>
  <div id="app">
    {{timestamp}} <br>
    {{timestamp | fmtDate}}
    <div :title="title | fmtTitle">过滤器</div>
  </div>
  <script>
    // 过滤器的声明以及全局注册
    Vue.filter('fmtDate', (timestamp) => {
      return new Date(timestamp).toLocaleString()
    })

    // Vue.filter('fmtTitle', (title) => {
    //   return title.toUpperCase()
    // })

    // 过滤器函数的声明
    let filter1 = (title) => {
      return title.toUpperCase()
    }

    let vm = new Vue({
      el: '#app',
      data: {
        timestamp: 1634010353655,
        title: 'hello filter'
      },
      methods: {},
      // 局部注册过滤器
      filters: {
        'fmtTitle': filter1
      }
    })
  </script>
</body>

</html>